package com.yc.hotel.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yc.hotel.dto.OrderInfoDTO;
import com.yc.hotel.enums.ResultEnum;
import com.yc.hotel.order.feign.IOrderInfoFeignClient;
import com.yc.hotel.vo.ResultVO;

@RestController
@RequestMapping("/order")
public class OrderInfoFeignController {

	@Autowired
	private IOrderInfoFeignClient orderInfoService;
	
	@PostMapping("/outOrder")
	public ResultVO outOrder(@RequestParam String ono,@RequestParam  String price) {

		int result = orderInfoService.outOrder(ono, price);
		if(result > 0) {
			return new ResultVO(ResultEnum.SUCCESS);
		}
		
		return new ResultVO(ResultEnum.ERROR);
		
	};
	
	@PostMapping("/closeOrder")
	public ResultVO closeOrder(@RequestParam String ono,@RequestParam  String rno) {

		int result = orderInfoService.closeOrder(ono, rno);
		if(result > 1) {
			return new ResultVO(ResultEnum.SUCCESS, result);
		}
		
		return new ResultVO(ResultEnum.ERROR);
	};
	
	@PostMapping("/check")//商家确认订单
	public ResultVO check(@RequestParam String rno,@RequestParam  String tno,@RequestParam  String status) {
		int result = orderInfoService.check(rno, tno, status);
		
		if(result > 0) {
			return new ResultVO(ResultEnum.SUCCESS);
		}
		
		return new ResultVO(ResultEnum.ERROR);
	};
	
	@PostMapping("/finds")
	public ResultVO finds(@RequestParam Map<String, Object> map) {
		List<OrderInfoDTO> orders = orderInfoService.finds(map);
		return new ResultVO(ResultEnum.SUCCESS, orders);
	};
}
